class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        vector<int> hash(256,0);
        int n=s.size();
        int max=0;
        int i=0;
        int j=-1;
        while(j<n-1)
        {
            j++;
            hash[s[j]]++;
            while(hash[s[j]]>1)
            {
                hash[s[i]]--;
                i++;
            }
            if(j-i+1>=max)
                max=j-i+1;
        }
        return max;
    }
};